package com.xnyzc.lhy.order.controller.mq;

import com.xnyzc.lhy.common.constant.MqConstant;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.penum.EDispatchType;
import com.xnyzc.lhy.order.entity.mq.OrderParam;
import com.xnyzc.lhy.order.entity.param.order.OrderDetailParam;
import com.xnyzc.lhy.order.entity.param.synchronization.LocationSyncParam;
import com.xnyzc.lhy.order.entity.param.synchronization.RealtimeFeeSyncParam;
import com.xnyzc.lhy.order.entity.param.synchronization.StatusCallbackParam;
import com.xnyzc.lhy.order.entity.system.OaSysDispatchLog;
import com.xnyzc.lhy.order.mq.MqDispatchLogProducer;
import com.xnyzc.lhy.order.mq.MqOrderProducer;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * feign调用mq
 *
 * @author zhengxu
 */
@RestController
@RequestMapping(value = "didi/mq")
public class MqController {

    @Autowired
    private MqOrderProducer mqOrderProducer;

    @Autowired
    private MqDispatchLogProducer dispatchLogProducer;

    /**
     * 筛选司机
     *
     * @param orderParam
     * @return
     */
    @PostMapping(value = "/getMqDriver")
    public Rv getMqDriver(@ApiParam(name = "orderNo", value = "订单号") @RequestBody com.xnyzc.lhy.order.entity.param.order.OrderParam orderParam) {
        return mqOrderProducer.sendMsg(orderParam);
    }

    /**
     * 司机调度列表
     *
     * @param orderParam
     * @return
     */
    @PostMapping(value = "/generateOrderList")
    public void generateOrderList(@ApiParam(name = "orderNo", value = "订单号") @RequestBody com.xnyzc.lhy.order.entity.param.order.OrderParam orderParam) {
        mqOrderProducer.sendMsg(orderParam, MqConstant.DIDI_GENERATE_ORDER_LIST);
    }

    @PostMapping(value = "/dispatchLog")
    public void dispatchLog(@RequestBody OaSysDispatchLog orderDetailParam) {
        Integer type = orderDetailParam.getType();
        String desc = EDispatchType.findDescByType(type);
        dispatchLogProducer.sendMsg(orderDetailParam, desc);
    }

    /**
     * 司机抢单结果保护机制
     *
     * @param orderDetailParam
     */
    @PostMapping(value = "/getDidiSheet")
    public void getDidiSheet(@RequestBody OrderDetailParam orderDetailParam) {
        mqOrderProducer.sendMsg(orderDetailParam, MqConstant.DIDI_GRAB_SHEET_TAG);
    }

    /**
     * 创建滴滴订单
     *
     * @param createOrderParam 创建订单参数
     */
    @PostMapping(value = "/createDidiOrder")
    public void createDidiOrder(@RequestBody OrderParam createOrderParam) {
        mqOrderProducer.sendMsg(createOrderParam, MqConstant.DIDI_CREATE_ORDER);
    }

    /**
     * 司机位置同步(滴滴)
     *
     * @param locationSyncParam
     */
    @PostMapping(value = "/driverPositionSync")
    public void driverPositionSync(@ApiParam(name = "locationSyncParam", value = "位置信息") @RequestBody LocationSyncParam locationSyncParam) {
        mqOrderProducer.sendMsg(locationSyncParam, MqConstant.DRIVER_LOCATION_SYNC);
    }

    /**
     * 实时计价同步(滴滴)
     *
     * @param realtimeFeeSyncParam
     */
    @PostMapping(value = "/realtimeFeeSync")
    public void realtimeFeeSync(@ApiParam(name = "realtimeFeeSyncParam", value = "价格信息") @RequestBody RealtimeFeeSyncParam realtimeFeeSyncParam) {
        mqOrderProducer.sendMsg(realtimeFeeSyncParam, MqConstant.REAL_TIME_FEE_SYNC);
    }

    /**
     * 司机状态同步(滴滴)
     *
     * @param statusCallbackParam
     */
    @PostMapping(value = "/statusCallback")
    public void statusCallback(@ApiParam(name = "statusCallbackParam", value = "司机状态信息") @RequestBody StatusCallbackParam statusCallbackParam) {
        mqOrderProducer.sendMsg(statusCallbackParam, MqConstant.STATUS_CALL_BACK_SYNC);
    }

}
